/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.07.30
 *Time:00:19
 */

import java.util.*;

//名字比较器
class nameComparator implements Comparator<String>{
    @Override
    public int compare(String o1, String o2) {
        return o1.compareTo(o2);
    }
}
//ArrayList的使用
public class Main{
    //洗牌算法
    public static void main(String[] args) {

        List<card> list =  cardDemo.buyDeck();
        //打印
        System.out.println("洗牌前："+list);
        //洗牌
        cardDemo.shuffle(list);
        System.out.println();
        //打印
        System.out.println("洗牌后：" + list);

        //三个人轮流抓牌，每人抓取5张牌
        List<List<card>> hands = new ArrayList<>();
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());

        //循环抓牌
        Random random = new Random();
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //抽取第一张牌
                hands.get(j).add(list.get(0));
                //list--
                list.remove(0);
            }
        }
        //每个人抓取的牌
        System.out.println("第一个人抓取的牌:" + hands.get(0));
        System.out.println("第二个人抓取的牌:" + hands.get(1));
        System.out.println("第三个人抓取的牌:" + hands.get(2));
        //剩余的牌
        System.out.println("================================");
        System.out.println("剩余的牌：" + list);
    }
    //杨辉三角
    public List<List<Integer>> generate(int numRows) {
        //常见一个List接口
        List<List<Integer>> ret = new ArrayList<>();

        //杨辉三角的首行元素
        List<Integer> list = new ArrayList<>();
        list.add(0);
        //将首行元素赋值给ret
        ret.add(list);

        //杨辉三角的2到numRows行
        for (int i = 1; i < numRows; i++) {
            //创建List接口
            List<Integer> tem = new ArrayList<>();
            //添加首个元素
            tem.add(0);
            //创建每一行中具体的元素（除了首尾）
            List<Integer> t = ret.get(i - 1);
            for (int j = 1; j < i; j++) {
                Integer integer = t.get(j - 1) + t.get(j);
                //添加
                tem.add(integer);
            }
            //添加末尾元素
            tem.add(0);
            //赋值
            ret.add(tem);
        }
        //返回ret
        return ret;
    }
    //循环打印的几种方法
    public static void main2(String[] args) {
        //for循环
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        Object[] objects = arrayList.toArray();
        for (int i = 0; i < objects.length; i++) {
            System.out.print(objects[i] + " ");
        }
        System.out.println();
        System.out.println("========================");
        //for-each循环
        for(Object o : objects){
            System.out.print(o + " ");
        }
        System.out.println();
        System.out.println("++++++++++++++++++++++++");
        //迭代器
        Iterator<Integer> it = arrayList.listIterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }

    }

    //常见方法的使用
    public static void main1(String[] args) {
      //实例化一个泛型顺序表
        List<String> list = new ArrayList<String>();

        //调用Add方法
        list.add("Java数据结构！");
        list.add(1,"Java EE初阶！");
        list.add(2,"Java EE进阶！");
        //删除
        list.remove("Java数据结构！");
        //修改
        list.set(0,"Java EE初阶");
        list.set(1,"Java EE进阶");
        //查找
        String str1 = list.get(0);
        String str2 = list.get(1);
        //排序:参数是一个比较器
        nameComparator nameComparator = new nameComparator();
        list.sort(nameComparator);
         //打印
        System.out.println(list);

    }
}
